package org.example.thread;

import org.apache.tomcat.util.threads.ThreadPoolExecutor;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

public class CompleTableFutureDemo03 {
   static AtomicInteger count  = new AtomicInteger(10);
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService =
                new ThreadPoolExecutor(8,16,30000, TimeUnit.MILLISECONDS,
                        new LinkedBlockingQueue<>(100),new ThreadPoolExecutor.AbortPolicy());

        //第一个
        CompletableFuture<Integer> completableFuture01 =
                //提供一个线程的传值为100 ，并提供给线程池管理
                CompletableFuture.supplyAsync(()->{
                            count.incrementAndGet();
                            try {
                                TimeUnit.SECONDS.sleep(1);

                            } catch (InterruptedException e) {
                                throw new RuntimeException(e);
                            }
                            return count.get();
                        },
                executorService);
        //第一个
        CompletableFuture<Integer> completableFuture02 =
                CompletableFuture.supplyAsync(()->{
                    count.incrementAndGet();
                    return count.get();
                },executorService);

        CompletableFuture<Integer> completableFuture03 = completableFuture01.thenCombineAsync(completableFuture02, (x1, x2) -> {
            return x1 + x2;
        }, executorService);
        System.out.println(completableFuture03.get());
        executorService.shutdown();

    }
}
